﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace QuTouTiaoAssist
{
    public partial class FrmIncomeStatistics : Form
    {
        private string[] m_names;
        private double[] m_values;

        public FrmIncomeStatistics(Dictionary<string,double> dic)
            : this(dic.Keys.ToArray(),dic.Values.ToArray())
        {
        }

        public FrmIncomeStatistics(string[] names, double[] values):this()
        {
            this.m_names = names;
            this.m_values = values;
        }

        private FrmIncomeStatistics()
        {
            InitializeComponent();
        }

        private void FrmIncomeStatistics_Load(object sender, EventArgs e)
        {
            Chart chart1 = new Chart();
            chart1.Dock = DockStyle.Fill;
            this.Controls.Add(chart1);

            //添加标题
            chart1.Titles.Add(this.Text);
            //添加ChartArea，用于显示图表
            chart1.ChartAreas.Add("chartArea1");
            //添加Series，用于添加图表数据、样式
            chart1.Series.Add("series1");
            //添加Legend，用于显示图例
            chart1.Legends.Add("legend1");

            chart1.Series["series1"].ChartType = SeriesChartType.Pie;
            chart1.Series["series1"].IsValueShownAsLabel = true; //显示值
            chart1.Series["series1"].Legend = "legend1";
            chart1.Series["series1"].Points.DataBindXY(this.m_names, this.m_values);
        }

        private void FrmIncomeStatistics_Deactivate(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
